package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.ActorDto;
import com.hualude.roadsign.model.ActorEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;


import java.util.List;

/**
 * Created by xu-jiaHui on 2017/4/7.
 */
public interface ActorRepository extends CrudRepository<ActorEntity, Long> {
    /**
     * @Description: 获取角色信息用于角色分配
     * @Author: xu-jiaHui
     * @Date: 2017/4/7 20:06
     */
    @Query(value = "select new com.hualude.roadsign.dto.ActorDto(a.actorId,a.actorName,a.actorRemarks) from ActorEntity a" +
            " where concat(a.actorName,a.actorId) like  CONCAT('%',:strSearch,'%')")
    public List<ActorDto> getActor4Dt(@Param("strSearch") String strSearch) throws Exception;

    @Query(value = "select count(*) from ActorEntity a where  a.actorId<>1 and concat(a.actorName,a.actorId) like  CONCAT('%',:strSearch,'%')")
    public Integer getActorCount4Dt(@Param("strSearch") String strSearch) throws Exception;

    /**
     * @Description: 更改角色信息
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 13:01
     */
    @Modifying
    @Query(value = "update ActorEntity a set a.actorName = ?1,a.actorRemarks = ?2 where a.actorId = ?3")
    public Integer updateActorById(String actorName, String actorRemarks, Integer actorId) throws Exception;

    /**
     * @Description: 删除角色
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 13:22
     */

    @Modifying
    @Query(value = "delete from ActorEntity a where a.actorId = ?1")
    public Integer deleteActorById(Integer actorId) throws Exception;

    /**
     * @Description: 获取角色列表（不包括系统管理员和主管管理员）
     * @Author: xu-jiaHui
     * @Date: 2017/4/28 1:34
     */
    @Query(value = "select new com.hualude.roadsign.dto.ActorDto(actorId,actorName) from ActorEntity where actorId<>1 and actorId<>7")
    public List<ActorDto> getActor4Select() throws Exception;


}
